package com.tju.shortlink.project.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tju.shortlink.project.common.convention.result.Result;
import com.tju.shortlink.project.common.convention.result.Results;
import com.tju.shortlink.project.dto.req.ShortLinkGroupStatsAccessRecordReqDTO;
import com.tju.shortlink.project.dto.req.ShortLinkGroupStatsReqDTO;
import com.tju.shortlink.project.dto.req.ShortLinkStatsAccessRecordReqDTO;
import com.tju.shortlink.project.dto.req.ShortLinkStatsReqDTO;
import com.tju.shortlink.project.dto.resp.ShortLinkStatsAccessRecordRespDTO;
import com.tju.shortlink.project.dto.resp.ShortLinkStatsRespDTO;
import com.tju.shortlink.project.service.ShortLinkStatsService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Tag(name = "短链接监控相关接口")
@RequestMapping("/api/short-link/v1/stats")
@RequiredArgsConstructor
public class LinkStatsController {

    private final ShortLinkStatsService shortLinkStatsService;

    /**
     * 访问单个短链接指定时间内监控数据
     */
    @Operation(summary = "访问单个短链接指定时间内监控数据")
    @GetMapping
    public Result<ShortLinkStatsRespDTO> shortLinkStats(ShortLinkStatsReqDTO requestParam) {
        return Results.success(shortLinkStatsService.oneShortLinkStats(requestParam));
    }

    /**
     * 访问单个短链接指定时间内监控数据
     */
    @Operation(summary = "访问单个分组指定时间内监控数据")
    @GetMapping("group")
    public Result<ShortLinkStatsRespDTO> groupShortLinkStats(ShortLinkGroupStatsReqDTO requestParam) {
        return Results.success(shortLinkStatsService.groupShortLinkStats(requestParam));
    }

    @Operation(summary = "分页查询指定时间内短链接访问记录")
    @GetMapping("access-record")
    public Result<IPage<ShortLinkStatsAccessRecordRespDTO>> shortLinkStatsAccessRecord(ShortLinkStatsAccessRecordReqDTO requestParam) {
        return Results.success(shortLinkStatsService.shortLinkStatsAccessRecord(requestParam));
    }

    @Operation(summary = "分页查询指定时间内指定分组的短链接访问记录")
    @GetMapping("access-record/group")
    public Result<IPage<ShortLinkStatsAccessRecordRespDTO>> shortLinkGroupStatsAccessRecord(ShortLinkGroupStatsAccessRecordReqDTO requestParam) {
        return Results.success(shortLinkStatsService.shortLinkGroupStatsAccessRecord(requestParam));
    }

}
